﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class NhanVien_QuanLySinhVien : System.Web.UI.Page
{
    DataClassesDataContext data = new DataClassesDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadThongTin();
            //LoadThongtinGiangVien();
            LoadThongTinSinhVien();
        }
    }

    private void LoadThongTin()
    {
        ddlMonHoc.DataSource = data.tbl_MONHOCs;
        ddlMonHoc.DataTextField = "TenMonHoc";
        ddlMonHoc.DataValueField = "MsMonHoc";
        ddlMonHoc.DataBind();

        string msgv = Session["TenDangNhap"].ToString();
        string msmh = ddlMonHoc.SelectedValue.ToString();

        var query = from p in data.tbl_LOPTCs
                    join q in data.tbl_PHANCONGVIECs on p.MsLopTC equals q.MsLopTC
                    where p.MsMonHoc == msmh && q.MsGiangVien == msgv
                    select p; 
        
        ddlLopTC.DataSource = query;
        ddlLopTC.DataTextField = "MsLopTC";
        ddlLopTC.DataValueField = "MsLopTC";
        ddlLopTC.DataBind();
    }

    private void LoadThongTinSinhVien()
    {
        string msloptc = ddlLopTC.SelectedValue.ToString();

        var dssv = from p in data.tbl_DANGKYLOPTCs
                   where p.MsLopTC == msloptc
                   select p;
        GridView1.DataSource = dssv;
        GridView1.DataBind();
    }

    //private void LoadThongtinGiangVien()
    //{
    //    if (Request.QueryString["MSGV"] != null)
    //    {
    //        string msgv = Request.QueryString["MSGV"];
    //        var gvs = from p in data.tbl_GIANGVIENs
    //                  where p.MsGiangVien == msgv
    //                  select p;
    //        foreach (tbl_GIANGVIEN gv in gvs)
    //        {
    //            //txtHoTenGV.Text = gv.TenGiangVien;
    //        }
    //        //txtMSGV.Text = msgv;
    //        //txtMSGV.Enabled = false;

    //    }
    //    else
    //    {
    //    }
    //}

   
    protected void ddlMonHoc_SelectedIndexChanged(object sender, EventArgs e)
    {
        string msgv = Session["TenDangNhap"].ToString();
        string msmh = ddlMonHoc.SelectedValue.ToString();

        var query = from p in data.tbl_LOPTCs
                    join q in data.tbl_PHANCONGVIECs on p.MsLopTC equals q.MsLopTC
                    where p.MsMonHoc == msmh && q.MsGiangVien==msgv
                    select p;

        ddlLopTC.DataSource = query;
        ddlLopTC.DataTextField = "MsLopTC";
        ddlLopTC.DataValueField = "MsLopTC";
        ddlLopTC.DataBind();

        LoadThongTinSinhVien();
    }
    protected void ddlLopTC_SelectedIndexChanged(object sender, EventArgs e)
    {
        LoadThongTinSinhVien();
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "this.setAttribute('bgColor', this.style.backgroundColor); this.style.backgroundColor = '#FF6600';");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor = this.getAttribute('bgColor');");
        }
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {

    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        LoadThongTinSinhVien();
    }
}
